dnl -*- mode: Autoconf; -*-

dnl -----------------------------------------------------------------------------------------
dnl option for converage tool
dnl -----------------------------------------------------------------------------------------

AC_ARG_ENABLE(gcov,
  AS_HELP_STRING([--enable-gcov], [enables gnu coverage (default: no)]),
  tr_COVERAGE="${enableval:-yes}",
  tr_COVERAGE=no
)

if test "x$tr_COVERAGE" = xyes;  then
  if test "x$GCC" = xyes; then
    GCOV_CXXFLAGS="-fprofile-arcs -ftest-coverage"
    GCOV_CFLAGS="-fprofile-arcs -ftest-coverage"
    GCOV_LDFLAGS=""
    GCOV_LIBS="-lgcov"
  else
    AC_MSG_ERROR([do not how to enable coverage compilation])
  fi
fi

AM_CONDITIONAL(ENABLE_GCOV, test "x$tr_COVERAGE" = xyes)

AC_SUBST(GCOV_CXXFLAGS)
AC_SUBST(GCOV_CFLAGS)
AC_SUBST(GCOV_LDFLAGS)
AC_SUBST(GCOV_LIBS)

CFLAGS="${CFLAGS} ${GCOV_CFLAGS}"
CXXFLAGS="${CXXFLAGS} ${GCOV_CXXFLAGS}"
LDFLAGS="${LDFLAGS} ${GCOV_LDFLAGS}"
LIBS="${LIBS} ${GCOV_LIBS} "

dnl -----------------------------------------------------------------------------------------
dnl informational output
dnl -----------------------------------------------------------------------------------------

if test "x$tr_COVERAGE" = xyes;  then
  FLAG_INFO="$FLAG_INFO|GCOV_CXXFLAGS: ${GCOV_CXXFLAGS}"
  FLAG_INFO="$FLAG_INFO|GCOV_LDFLAGS:  ${GCOV_LDFLAGS}"
  FLAG_INFO="$FLAG_INFO|GCOV_LIBS:     ${GCOV_LIBS}"
fi
